package exemplo.teste;


import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import exemplo.database.ProductDAO;
import exemplo.model.Product;

public class ProductDAOTest {


	@Test
	public final void testAdd() throws Exception{
	
		System.out.println("add");
		Product prod = new Product();
		prod.setCode(100);
		prod.setName("Product Test");
		prod.setNumberOfItens(13);
		prod.setPrice(12f);
		ProductDAO prodDAO = new ProductDAO();
		
		boolean expResult = false;
		boolean result = prodDAO.add(prod);
		Assert.assertEquals(expResult, result);
	}

	@Test
	public final void testSet() throws Exception{
		System.out.println("set");
		Product prod = new Product();
		prod.setCode(100);
		prod.setName("Product Test set");
		prod.setNumberOfItens(13);
		prod.setPrice(12f);
		ProductDAO prodDAO = new ProductDAO();
		
		boolean expResult = true;
		boolean result = prodDAO.set(prod);
		Assert.assertEquals(expResult, result);
	}

	@Test
	public final void testDelete() throws Exception{
		System.out.println("delete");
		Product prod = new Product();
		prod.setCode(100);
		prod.setName("Product Test set");
		prod.setNumberOfItens(13);
		prod.setPrice(12f);
		ProductDAO prodDAO = new ProductDAO();
		
		boolean expResult = true;
		boolean result = prodDAO.delete(prod);
		Assert.assertEquals(expResult, result);
	}

	@Test
	public final void testGetAllProducts() throws Exception{
		System.out.println("getAllProducts");
		ProductDAO dao = new ProductDAO();
		List<Product> list = dao.getAllProducts();
		Assert.assertTrue(list.size() == 3);
	}

	@Test
	public final void testGetByCode() throws Exception{
		System.out.println("getByCode");
		int code = 1;
		ProductDAO dao = new ProductDAO();
		Product prod = dao.getByCode(code);
		Assert.assertNotNull(prod);
	}
}
